<?php
/**
 * gcFramework
 *
 * Development framework for PHP 5 or newer
 *
 * @package		gcFramework
 * @author		Adam Martin
 * @copyright	Copyright (c) 2006
 * @link		http://www.gcFramework.com
 */


class gcYaml {
	
	function load($input){
		if (function_exists('syck_load')){
      		$array = syck_load(BASEPATH."/".FRAMEWORK."/data/".$input.".yml");
			return (is_array($array)) ? $array : array();
    	} else {
    		require_once(BASEPATH."/".FRAMEWORK."/lib/spyc/spyc.php5");
      		$spyc = new Spyc();
        	return $spyc->load(BASEPATH."/".FRAMEWORK."/data/".$input.".yml");
		}
	}
	
	function loadconfig($input){
		if (function_exists('syck_load')){
      		$array = syck_load(BASEPATH."/".APP."/config/".$input.".yml");
			return (is_array($array)) ? $array : array();
    	} else {
    		require_once(BASEPATH."/".FRAMEWORK."/lib/spyc/spyc.php5");
      		$spyc = new Spyc();
        	return $spyc->load(BASEPATH."/".APP."/config/".$input.".yml");
		}
	}
		
	function showlog(){
		if (function_exists('syck_load')){
      		$array = syck_load(BASEPATH."/".FRAMEWORK."/logs/main.yml");
			return (is_array($array)) ? $array : array();
    	} else {
    		require_once(BASEPATH."/".FRAMEWORK."/lib/spyc/spyc.php5");
      		$spyc = new Spyc();
        	return $spyc->load(BASEPATH."/".APP."/logs/main.yml");
		}
	}
		
	function logger($array, $file){
			$log = new Spyc();
			$logentry = $log->dump($array);
			$handle = fopen(BASEPATH."/".APP."/logs/".$file.".yml" , "a+");
			if (fwrite($handle, $logentry) === FALSE) {
       			echo "Cannot write to file ($filename)";
       			exit;
   			}
  			
  			fclose($handle);
			return;
	}	
	
	function country($country){
		$array = self::load('countries');
		return $array[$country];
	}	

}
?>
